<?php

namespace Biz\model\salesRebate;

use Doraemon\pockets\datebase\BaseDbModel;

class SalesPersonal extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_sales_rebate';

    const _DATABASE_ = 'biz_sales_rebate';

    const _TABLE_NAME = 'sales_personal';

    const STATUS_NORMAL = 0;//签约中
    const STATUS_SIGNED = 1;//已签约
    const STATUS_DELETE = 9;

    const USER_LIST = [
        46321=> 3965.55,
        2870346=> 9393.3,
        40067=> 10241,
        1287164=> 2052,
        75480=> 19094,
        967488=> 1251.15,
        5173225=> 9190.3,
        5775097=> 1931,
        632408=> 2762.78,
        381517=> 1374.51,
        2004005=> 2006.2,
        1505229=> 2945,
        6337804=> 2032.05,
        2205315=> 708.7,
        11906=> 100,
        5766082=> 100
    ];


    public static function getAllByWhere($files = '*', $where = [])
    {
        $data = self::select($files, $where);
        return $data;
    }

    public static function getOneByWhere($files = '*', $where = [])
    {
        $data = self::get($files, $where);
        return $data;
    }

    public static function save($data)
    {
        if ($data['uid']) {
            $getOne = self::get('id', ['uid' => $data['uid']]);
            if ($getOne) {
                if ($data['status'] != self::STATUS_DELETE) {
                    try {
                        self::update($data, ['id' => $getOne]);
                        return $getOne;
                    } catch (Exception $e) {
                        return false;
                    }
                }
            } else {
                try {
                    self::insert($data);
                    return self::id();
                } catch (Exception $e) {
                    return false;
                }
            }
        } else {
            return false;
        }

    }

    public static function IsSigned($uid)
    {
        $info = self::get(['status'], ['uid' => $uid]);
        if ($info && $info['status'] == self::STATUS_SIGNED) {
            return true;
        }
        return false;
    }

    public static function updateData($data, $where)
    {
        $ret = self::update($data, $where);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return true;
    }
}